<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="billList">
      <el-table-column label="账单id" align="center" prop="billId" v-if="true"/>
      <el-table-column label="入住id" align="center" prop="checkinId" />
      <el-table-column label="前台id" align="center" prop="workerID" />
      <el-table-column label="房间费用" align="center" prop="roomCost" />
      <el-table-column label="服务费用" align="center" prop="serviceCost" />
      <el-table-column label="打折" align="center" prop="billDiscount" />
      <el-table-column label="实际费用" align="center" prop="billActual" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listBill,myBillList } from "@/api/hotel/bill";

export default {
  name: "Bill",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      billList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        checkinId: undefined,
        roomCost: undefined,
        serviceCost: undefined,
        billDiscount: undefined,
        billActual: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        billId: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        checkinId: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        roomCost: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        serviceCost: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        billDiscount: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        billActual: [
          { required: true, message: "不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      myBillList(this.queryParams).then(response => {
        this.billList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        billId: undefined,
        checkinId: undefined,
        roomCost: undefined,
        serviceCost: undefined,
        billDiscount: undefined,
        billActual: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hotel/bill/export', {
        ...this.queryParams
      }, `bill_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
